package com.onemore.task.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.voovan.db.JdbcOperate;
import org.voovan.tools.log.Logger;

import com.alibaba.fastjson.JSONObject;
import com.onemore.task.JdbcGlobal;
import com.onemore.task.OneConfig;

public class ModelOneErpThd extends JdbcGlobal{
	final static private String fields[] = new String[] {"DJBH","RQ","DM2"};

	static public boolean isNotExist()
	{
		return validateTableExist("ONE_B2C_ERPWMS");
	}
	static public boolean isNotExist(String tableName)
	{
		return validateTableExist(tableName);
	}
	static public List<Map<String, Object>> getList(String starDate,String endDate) throws SQLException
    {
		String filterDate = "";
		Properties properties= OneConfig.getProperties();
		if(properties != null) {
			String str = null;
			if(starDate == null) {
				str = OneConfig.getProperties().getProperty("starDate");
				if(str != null) {
					starDate = str;
				}
			}
		}
		if(starDate != null && starDate.length() > 0) {
			filterDate = " AND RQ>='"+starDate+"'";
		}
		if(endDate != null && endDate.length() > 0) {
			filterDate = " AND RQ<='"+endDate+"'";
		}
		String sql = "select DJBH, CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from SPJHD WHERE ISNULL(DM2_1,'')=''"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from SPTHD WHERE ISNULL(DM2_1,'')='' "+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from QDDBD WHERE ISNULL(DM2_1,'')=''"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from QDTHD WHERE ISNULL(DM2_1,'')=''"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from SDPHD WHERE ISNULL(DM2_1,'')=''"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from SDTHD WHERE ISNULL(DM2_1,'')=''"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from SPYCD WHERE (ISNULL(DM2_1,'')='' OR ISNULL(DM1_1,'')='')"+filterDate+" union all select DJBH,CONVERT(VARCHAR(11),RQ,120) AS RQ,DM2 from CKTZD WHERE ISNULL(DM2_1,'')=''"+filterDate;
    	List<Map<String, Object>> manyMaps = null;
		manyMaps = getJdbcOperate().queryMapList(sql);
		return manyMaps;
	}
}
